package com.lancoo.znbkxx.teacher.ui.fragment

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.PopupWindow
import com.google.android.flexbox.AlignItems
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.adapter.SpacesItemDecoration
import com.lancoo.znbkxx.teacher.adapter.ZSdListAdapter
import com.lancoo.znbkxx.teacher.model.data.ImportKlg
import com.lancoo.znbkxx.teacher.utils.DensityUtils
import kotlinx.android.synthetic.main.fmt_publish_new.view.*
import kotlinx.android.synthetic.main.view_knowledge_point.view.*
import kotlinx.android.synthetic.main.view_knowledge_point.view.rv_zsd

/**
 * Created by wealive on 2021/3/11.
 *
 *
 */
class KnowledgePointWindow(val context: Context, val listener: View.OnClickListener,
                           val zsdList: List<ImportKlg>) :
        PopupWindow() {
    private var zsdAdapter: ZSdListAdapter

    init {
        val contentView = LayoutInflater.from(context).inflate(R.layout.view_knowledge_point, null)
        zsdAdapter = ZSdListAdapter(zsdList)
        val manager = FlexboxLayoutManager(context, FlexDirection.ROW,
                FlexWrap.WRAP).apply {
            alignItems = AlignItems.FLEX_START
        }
        contentView.tv_confirm.setOnClickListener(listener)
        contentView.iv_close.setOnClickListener(listener)
        contentView.rv_zsd.layoutManager = manager
        val hashMap = hashMapOf<String, Int>()
        hashMap[SpacesItemDecoration.TOP_SPACE] = DensityUtils.dp2px(context, 12f)
        hashMap[SpacesItemDecoration.LEFT_SPACE] = DensityUtils.dp2px(context, 10f)
        contentView.rv_zsd.addItemDecoration(SpacesItemDecoration(hashMap))
        contentView.rv_zsd.adapter = zsdAdapter
        this.contentView = contentView
        animationStyle = R.style.PopupWindow
        this.width = WindowManager.LayoutParams.MATCH_PARENT
        this.height = WindowManager.LayoutParams.WRAP_CONTENT
        this.isOutsideTouchable = false
        this.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        this.isFocusable = true
        update()
    }
}